<template>
  <div class="hello">
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="120">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="100">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="180">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="280">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        width="280">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="时间"
        width="280">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :page-size="pageSize"
      :current-page="currentPage"
      @current-change="getCurrentPage"
      :total="totals">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data () {
    return {
      tableData:[],
      pageSize:5,
      currentPage:1,
      totals:0
    }
  },
  methods:{
    handleEdit(){
      this.getStudents()
    },
    handleDelete(){
      this.getStudents()
    },
    getStudents(){
        this.$http.post("/student/list",{"currentPage":this.currentPage,"pageSize":this.pageSize}).then(res=>{
          this.tableData = res.data.data
          this.totals = res.data.totals
        }).catch(res=>{
        })
    },
    getCurrentPage(currentPage){
      this.currentPage = currentPage
      this.getStudents()
    }
  },
  mounted() {
    this.getStudents()
  }
}
</script>
